<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>个人主页</title>
	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
		<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
	<style>
	@font-face {
		  font-family: 'iconfont';  /* project id 416894 */
		  src: url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.eot');
		  src: url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.eot?#iefix') format('embedded-opentype'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.woff') format('woff'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.ttf') format('truetype'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.svg#iconfont') format('svg');
}
				
			body{
				margin: 0;
				padding: 0;
				background-color: #f3f3f3;
			}
			a{
				color: inherit;
				text-decoration: none;
			}
			a:hover{
				color: #3879d9;
				text-decoration: none;
			}
			.top{
				display: flex;
				width: 100%;
				height: 50px;
				background-color: white;
				position: fixed;
				top: 0;
				box-shadow: 0px 2px 5px #888888;
			}
			.mid{
				margin-top: 60px;
				margin-left: auto;
				margin-right: auto;
				width: 75%;
			}
		.logo{
			height: 40px;
			padding: 5px;
			padding-left: 200px;
		}
		
		.top_left{
			flex: 1;
		}
		
		.top_mid{
			flex: 1;
			font-family: "iconfont" !important;
			text-align: center;
			padding: 13px;
			padding-left: 15px;
		}
		
		.top_right{
			flex: 1;
		}
		
		.top_find{
			
			padding: 3px;
			
		}
		
		.top_img{
			width: 30px;
			height: 30px;
			background-color: blue;
		}
		
		.top_right{
			padding: 10px;
			padding-left: 80px;
		}
		.info{
			background: #fff;
			display: flex;
			padding: 16px;
			border-bottom: 1px solid #ccc;
		}
		.info_head{
			width: 100px;
		}
		.info_right{
			padding-left: 16px;
			padding-right: 16px;
			flex: 1;
		}
		.info_nickname{
			font-size: 18px;
			font-weight: bold;
		}
		.tabbar{
			background: #fff;
			border-bottom: 1px solid #ccc;
		}
		.tabbar_center{
			width: 50%;
			margin-left: auto;
			margin-right: auto;
			display: flex;
		}
		.tabitem{
			flex: 1;
			padding: 8px;
			text-align: center;
			cursor: pointer;
		}

		.tabitem_selected{
			border-bottom: 2px solid #00aaff;
			background: #cceeff;
		}

		.tabitem:hover{
			background: #cceeff;
		}
		.main{
			background: #fff;
			
		}
		.list_item{
			border-bottom: 1px solid #ccc;
		}
		.list_item_center{
			width: 70%;
			margin-left: auto;
			margin-right: auto;
		}
		.list_item_info{
			padding: 16px;
			display: flex;
		}
		.btn_user{
			padding: 8px;
			text-align: center;
			font-size: 14px;
			cursor: pointer;
			font-family: "iconfont" !important;
			color: #fff;
			background: #00aaff;
			margin-top: 8px;
		}
		.btn_user:hover{
			background: #22ccff;
		}

		.weibo_message{
			/*margin-top: 8px;*/
			background-color: white;
			min-height: 100px;
			/*box-shadow: 2px 3px 5px #888888;*/
		}
		
		.weibo_top{
			padding: 8px;
			padding-bottom: 5px;
			display: flex;
		}
		
		.weibo_message_img{
			width: 40px;
			height: 40px;
			background-color: black;
		}
		
		.weibo_message_nickname{
			margin-left: 8px;
			margin-top: 10px;
		}
		
		.div_message_mid{
			padding: 8px;
			padding-top: 5px;
		}
		
		.textarea_message{
			text-indent: 30px;
			padding-left: 8px;
			font-size: 15px;
			font-weight: bold;
		}
		
		.div_message_bottom{
			display: flex;
			/*padding: 8px;*/
			
		}
		
		
		.head_img{
			width: 50px;
			height: 50px;
		}
		
		.head_nickname{
			flex: 1;
			height: 50px;
		}
		.head_nickname_row{
			display: flex;
		}
		
		.head_nickname_size{
			font-size: 18px;
			font-weight: bold;
			flex: 1;
		}

		.delete_btn{
			width: 20px;
			font-family: "iconfont" !important;
			font-size: 18px;
			color: rgb(180,187,205);
			cursor: pointer;
		}
		.delete_btn:hover{
			color: #3879d9;
		}
		
		.btn_bottom{
			text-align: center;
			font-family: "iconfont" !important;
			flex: 1;
			cursor: pointer;
			padding: 8px;
		}

		.btn_bottom:hover{
			background: #cceeff;
		}

		.transmit{
			padding: 3px;
			background-color:#f3f3f3;
			margin-left: 40px;
			margin-right: 40px;
			margin-bottom: 5px;
		}
		
		.transmit_name{
			padding: 3px;
			font-size: 16px;
			font-weight: bold;
		}

		.like_btn_liked{
			color: #00aaff;
		}
		
		
		.time_size{
			
			color: rgb(180,187,205);
		}
		
		.transmit_name_content{
			padding: 3px;
			font-size: 15px;
			font-weight: bold;
		}
		
		.div_message_bottom{
			font-size: 15px;
			font-weight: 600;
		}
		#reblog_textarea{
			resize: none;
		}

		.bottom_row{
			text-align: center;
			padding-top: 16px;
			padding-bottom: 16px;
		}

		.load_more_btn{
			display:inline-block; 
			*display:inline; 
			*zoom:1;
			padding: 8px 24px 8px 24px;
			margin-left: auto;
			margin-right: auto;

			border: 1px solid #aaa;
			border-radius: 4px;
			color: #aaa;

			cursor: pointer;
		}

		</style>
</head>
<body>

<!-- <div class="top" >
		<div class="top_left">
			<img class="logo" src="img/logo.png" />
		</div>
		<div class="top_mid">
			<input class="top_find" type="text" />
			<span class="search_btn">&#xe6a7;</span>
		</div>
		<div class="top_right">
			<img class="top_img" src="img/back.png" />
		</div>
	</div> -->

<div id="nav_area"></div>

<div class="mid">
	<div class="info">
		<div class="info_head">
			<div class="info_head">
				
			</div>
			<img id="info_head_img" src="" style="background: #000; width: 100px; height: 100px;">
			<div class="btn_user" id="btn_head">&#xe602; 加载</div>

		</div>
		<div class="info_right">
			<div class="info_nickname" id="info_nickname">用户名</div>
			<li>地区: <span id="info_area"></span></li>
			<li>性别: <span id="info_sex"></span></li>
			<li>生日: <span id="info_birthday"></span></li>
			<li>个性签名: <span id="info_signature"></span></li>
		</div>
	</div>

	<div class="tabbar">
		<div class="tabbar_center">
			<div class="tabitem tabitem_selected" id="weibo_tab_item">
				<span class="user_self">我</span>的微博
			</div>
			<div class="tabitem" id="follow_tab_item">
				<span class="user_self">我</span>的关注(<span id="follow_num">0</span>)
			</div>
			<div class="tabitem" id="fans_tab_item">
				<span class="user_self">我</span>的粉丝(<span id="fans_num">0</span>)
			</div>
		</div>
	</div>
	
	<div class="main">
		<div id="weibo_tab_page">
			<!-- <div class="list_item">
				<div class="list_item_center">
					微博条目
				</div>
			</div> -->
		</div>

		<div id="follow_tab_page">
			<!-- <div class="list_item">
				<div class="list_item_center">
					<div class="list_item_info">
						<div class="info_head">
							<div class="info_head">
								<img src="" style="background: #000; width: 100px; height: 100px;">
							</div>
							<div class="btn_user btn_unfollow">&#xe628; 已关注</div>
						</div>
						<div class="info_right">
							<div class="info_nickname">用户名</div>
							<li>1</li>
							<li>1</li>
							<li>1</li>
							<li>1</li>
						</div>
					</div>
				</div> 
			</div> -->

		</div>

		<div id="fans_tab_page">
			<!-- <div class="list_item">
				<div class="list_item_center">
					粉丝条目
				</div>
			</div> -->

		</div>

		<div class="bottom_row">
			<div class="load_more_btn">
				点击加载更多
			</div>
		</div>
	</div>
	
</div>

<!-- 转发模态框 -->
	<div class="modal fade" id="reblogModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">转发微博</h4>
      </div>
      <div class="modal-body">
          <div class="form-group">
            <!-- <label for="message-text" class="control-label">微博内容</label> -->
            <textarea class="form-control" id="reblog_textarea" placeholder="转发理由..."></textarea>
            
          </div>
          	<div style="text-align: right;">
				<span id="reblog_word_counter">0</span> / 140
			</div>
          <div class="transmit"><div class="transmit_name">@<span id="modal_nickname">转发自某某某</span></div><div class="transmit_name" id="modal_content">原微博内容</div></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="reblog_submit_btn">发送</button>
      </div>
    </div>
  </div>
</div>

<!-- 删除模态框 -->
	<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">删除微博</h4>
      </div>
      <div class="modal-body">
          确认删除这条微博?
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-danger" id="delete_comfirm_btn">删除</button>
      </div>
    </div>
  </div>
</div>


<script src="nav.js"></script>

<script>
function getQueryString(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}


$(document).ready(function(){

	showNavBar();

	var uid = getQueryString("u");
	loadUserInfo(uid);

})

var currentTab = -1;

function switchTab(tab){
	$(".tabbar_center").children().removeClass("tabitem_selected");
	$(".main").children().hide();
	$(".bottom_row").show();

	switch(tab){
		case 0:
			$("#weibo_tab_item").addClass("tabitem_selected");
			$("#weibo_tab_page").show();
			if (currentTab != 0) {
				refreshWeiboList(thisUid);
			}
			break;
		case 1:
			$("#follow_tab_item").addClass("tabitem_selected");
			$("#follow_tab_page").show();
			if (currentTab != 1) {
				refreshFollowList(thisUid);
			}
			break;
		case 2:
			$("#fans_tab_item").addClass("tabitem_selected");
			$("#fans_tab_page").show();
			if (currentTab != 2) {
				refreshFansList(thisUid);
			}
			break;
		default:

			break;
	}
	currentTab = tab;
}

$("#weibo_tab_item").click(function(){
	switchTab(0);
})
$("#follow_tab_item").click(function(){
	switchTab(1);
})
$("#fans_tab_item").click(function(){
	switchTab(2);
})

var thisUid = null;
var thisFollowState = null;

function loadUserInfo(uid = null){
	var url = "userinfo.do";
	if (uid != null) {
		url = "userinfo.do?user_id=" + uid;
		
	}
	$.get(url, function(data){
		try{
			var jsonObj = JSON.parse(data);
			console.log(jsonObj);
			if (jsonObj.error == 0) {
				var thisData = jsonObj.data;
				var head_img = 'img/head/' + thisData.head_image + ".jpg";
				$("#info_head_img").attr("src", head_img);
				$("#info_nickname").html(thisData.nickname);
				$("#follow_num").html(thisData.follow_num);
				$("#fans_num").html(thisData.fans_num);
				$("#info_area").html(thisData.area);

				var sex = "保密";
				if (thisData.sex == 1) {
					sex = "男";
					if (uid != null) {
						$(".user_self").html("他");
					}
				}else if (thisData.sex == 2) {
					sex = "女";
					if (uid != null) {
						$(".user_self").html("她");
					}
				}else{
					if (uid != null) {
						$(".user_self").html("TA");
					}
				}
				$("#info_sex").html(sex);

				$("#info_birthday").html(thisData.birthday);
				$("#info_signature").html(thisData.signature);

				thisFollowState = thisData.follow_state;
				$("#btn_head").addClass(getActionBtnClass(thisData.follow_state)+"_head");
				$("#btn_head").html(getActionBtnText(thisData.follow_state));

				thisUid = uid;

				// $(".btn_alter").click(function(){
				// 	window.location.href = "data_alter.html";
				// })
				$(".btn_unfollow_head").hover(function(){
					$(this).html("&#xe606; 取消关注");
				}, function(){
					$(this).html("&#xe628; 已关注");
				})

				$(".btn_friend_head").hover(function(){
					$(this).html("&#xe606; 取消关注");
				}, function(){
					$(this).html("&#xe632; 互相关注");
				})

				// 获取url的参数t，切换到相应的tab页面
				var tab = getQueryString("t");
				// console.log(tab);
				if (tab != null) {
					try{
						var tabIndex = parseInt(tab);

						switchTab(tabIndex);
					}catch(ex){
						console.log(ex);
						switchTab(0);
					}
				}else{
					switchTab(0);
				}

			}else if (jsonObj.error == 220) {
				window.location.href = "login.html";
			}else{
				alert(jsonObj.msg);
			}
		}catch(ex){
			alert(ex);
		}
	})
}

var followListPage = 0;
var fansListPage = 0;
var itemPrePage = 20;

function refreshFollowList(uid = null){
	followListPage = 0;
	$("#follow_tab_page").html('');
	loadFollowList(uid);
}

function refreshFansList(uid = null){
	fansListPage = 0;
	$("#fans_tab_page").html('');
	loadFansList(uid);
}

function loadFollowList(uid = null){
	var url = 'listFollow.do?m='+followListPage*itemPrePage+'&n='+(followListPage+1)*itemPrePage;
	if (uid != null) {
		url += "&user_id=" + uid;
	}
	console.log(url);

	$.get(url, function(data){
		try{
			var jsonObj = JSON.parse(data);
			console.log(jsonObj);
			if (jsonObj.error == 0) {
				for (var i = 0; i < jsonObj.data.length; i++) {
					var thisData = jsonObj.data[i];
					var head_img = 'img/head/' + thisData.head_image + ".jpg";
					var sex = "保密";
					if (thisData.sex == 1) {
						sex = "男";
					}else if (thisData.sex == 2) {
						sex = "女";
					}

					$("#follow_tab_page").append('<div class="list_item">'+
				'<div class="list_item_center">'+
					'<div class="list_item_info">'+
						'<div class="info_head">'+
							'<div class="info_head">'+
								'<a href="person.html?u='+thisData.user_id+'" target="_blank"><img src="'+head_img+'" style="background: #000; width: 100px; height: 100px;"></a>'+
							'</div>'+
							(thisData.follow_state == 'self' ? '' : '<div class="btn_user '+getActionBtnClass(thisData.follow_state)+'" data-uid="'+thisData.user_id+'">'+getActionBtnText(thisData.follow_state)+'</div>')+
						'</div>'+
						'<div class="info_right">'+
							'<div class="info_nickname"><a href="person.html?u='+thisData.user_id+'" target="_blank">'+thisData.nickname+'</a></div>'+
							'<li>地区: '+thisData.area+'</li>'+
							'<li>性别: '+sex+'</li>'+
							'<li>生日: '+thisData.birthday+'</li>'+
							'<li>个性签名: '+thisData.signature+'</li>'+
						'</div>'+
					'</div>'+
				'</div>');
				}
				if (jsonObj.data.length != 0) {
					followListPage += 1;
					if (jsonObj.data.length < itemPrePage) {
						$(".load_more_btn").text("没有更多了");
					}else{
						$(".load_more_btn").text("点击加载更多");
					}
				}else{
					$(".load_more_btn").text("没有更多了");
				}
				
				bindBtnAction();


			}
		}catch(ex){

		}
	})
}

function loadFansList(uid = null){
	var url = 'listFans.do?m='+fansListPage*itemPrePage+'&n='+(fansListPage+1)*itemPrePage;
	if (uid != null) {
		url += "&user_id=" + uid;
	}

	$.get(url, function(data){
		try{
			var jsonObj = JSON.parse(data);
			console.log(jsonObj);
			if (jsonObj.error == 0) {
				for (var i = 0; i < jsonObj.data.length; i++) {
					var thisData = jsonObj.data[i];
					var head_img = 'img/head/' + thisData.head_image + ".jpg";
					var sex = "保密";
					if (thisData.sex == 1) {
						sex = "男";
					}else if (thisData.sex == 2) {
						sex = "女";
					}

					$("#fans_tab_page").append('<div class="list_item">'+
				'<div class="list_item_center">'+
					'<div class="list_item_info">'+
						'<div class="info_head">'+
							'<div class="info_head">'+
								'<a href="person.html?u='+thisData.user_id+'" target="_blank"><img src="'+head_img+'" style="background: #000; width: 100px; height: 100px;"></a>'+
							'</div>'+
							(thisData.follow_state == 'self' ? '' : '<div class="btn_user '+getActionBtnClass(thisData.follow_state)+'" data-uid="'+thisData.user_id+'">'+getActionBtnText(thisData.follow_state)+'</div>')+
						'</div>'+
						'<div class="info_right">'+
							'<div class="info_nickname"><a href="person.html?u='+thisData.user_id+'" target="_blank">'+thisData.nickname+'</a></div>'+
							'<li>地区: '+thisData.area+'</li>'+
							'<li>性别: '+sex+'</li>'+
							'<li>生日: '+thisData.birthday+'</li>'+
							'<li>个性签名: '+thisData.signature+'</li>'+
						'</div>'+
					'</div>'+
				'</div>');
				}

				if (jsonObj.data.length != 0) {
					fansListPage += 1;
					if (jsonObj.data.length < itemPrePage) {
						$(".load_more_btn").text("没有更多了");
					}else{
						$(".load_more_btn").text("点击加载更多");
					}
					
				}else{
					$(".load_more_btn").text("没有更多了");
				}
				
				bindBtnAction();

				
			}
		}catch(ex){

		}
	})
}

function getActionBtnClass(state){
	switch(state){
		case 'self':
			return 'btn_alter';
		case 'followed':
			return 'btn_unfollow';
		case 'fans':
			return 'btn_follow';
		case 'stranger':
			return 'btn_follow';
		case 'friend':
			return 'btn_friend';
		default:
			return 'btn_follow';
	}
}

function getActionBtnText(state){
	switch(state){
		case 'self':
			return '&#xe603; 修改资料';
		case 'followed':
			return '&#xe628; 已关注';
		case 'fans':
			return '&#xe616; 关注';
		case 'stranger':
			return '&#xe616; 关注';
		case 'friend':
			return '&#xe632; 互相关注';
		default:
			return '&#xe616; 关注';
	}

}

$("#btn_head").click(function(){
	if (thisFollowState == null) {
		window.location.href = "login.html";
		return;
	}

	if (thisFollowState == 'self') {
		window.location.href = "data_alter.html";
		return;
	}

	if (thisUid == null) {
		alert('系统异常，请稍后刷新页面重试');
		return;
	}


	if (thisFollowState == 'stranger' || thisFollowState == 'fans') {
		followUser(thisUid, $(this), true);
	}else if (thisFollowState == 'followed' || thisFollowState == 'friend') {
		unFollowUser(thisUid, $(this), true);
	}
})

function bindBtnAction(){
	$(".btn_follow,.btn_unfollow,.btn_friend").unbind();
	// $(".btn_follow,.btn_unfollow,.btn_friend").unbind('hover');
	//.unbind('mouseenter').unbind('mouseleave')
	$(".btn_follow").click(function(){
		var uid = $(this).attr("data-uid");
		followUser(uid, $(this));
	})

	$(".btn_unfollow,.btn_friend").click(function(){
		var uid = $(this).attr("data-uid");
		unFollowUser(uid, $(this));
	})

	$(".btn_unfollow").hover(function(){
		$(this).html("&#xe606; 取消关注");
	}, function(){
		$(this).html("&#xe628; 已关注");
	})

	$(".btn_friend").hover(function(){
		$(this).html("&#xe606; 取消关注");
	}, function(){
		$(this).html("&#xe632; 互相关注");
	})
}

function bindHeadBtnAction(){
	$("#btn_head").unbind("mouseenter").unbind("mouseleave");
	$(".btn_unfollow_head").hover(function(){
		$(this).html("&#xe606; 取消关注");
	}, function(){
		$(this).html("&#xe628; 已关注");
	})

	$(".btn_friend_head").hover(function(){
		$(this).html("&#xe606; 取消关注");
	}, function(){
		$(this).html("&#xe632; 互相关注");
	})
}

function followUser(userid, btn, master = false){
	console.log("follow: "+userid);
	$.post('doFollow.do', {
		user_id: userid
	}, function(data){
		try{
			console.log(data);
			var jsonObj = JSON.parse(data);
			if (jsonObj.error == 0) {
				
				btn.html(getActionBtnText(jsonObj.data.follow_state));

				if (master) {
					btn.removeClass("btn_unfollow_head");
					btn.addClass(getActionBtnClass(jsonObj.data.follow_state)+'_head');
					thisFollowState = jsonObj.data.follow_state;
					bindHeadBtnAction();
					$("#fans_num").text(parseInt($("#fans_num").text()) + 1);
					if (currentTab == 2) {
						refreshFansList(thisUid);
					}
				}else{
					btn.removeClass("btn_follow");
					btn.addClass(getActionBtnClass(jsonObj.data.follow_state));
					bindBtnAction();
				}


				
			}else if (jsonObj.error == 220) {
				window.location.href = "login.html";
			}else{
				alert('系统异常，请稍后刷新页面重试');
			}
		}catch(ex){
			alert('系统异常，请稍后刷新页面重试');
		}
	})
}

function unFollowUser(userid, btn, master = false){
	console.log("unfollow: "+userid);
	$.post('unFollow.do', {
		user_id: userid
	}, function(data){
		try{
			console.log(data);
			var jsonObj = JSON.parse(data);
			if (jsonObj.error == 0) {
				
				if (master) {
					btn.removeClass("btn_unfollow_head");
					btn.removeClass("btn_friend_head");
					btn.addClass(getActionBtnClass(jsonObj.data.follow_state)+'_head');
					thisFollowState = jsonObj.data.follow_state;
					bindHeadBtnAction();
					$("#fans_num").text(parseInt($("#fans_num").text()) - 1);

					if (currentTab == 2) {
						refreshFansList(thisUid);
					}
				}else{
					btn.removeClass("btn_unfollow");
					btn.removeClass("btn_friend");
					btn.addClass(getActionBtnClass(jsonObj.data.follow_state));
					bindBtnAction();
				}
				
				btn.html(getActionBtnText(jsonObj.data.follow_state));
				bindBtnAction();
			}else if (jsonObj.error == 220) {
				window.location.href = "login.html";
			}else{
				alert('系统异常，请稍后刷新页面重试');
			}
		}catch(ex){
			alert('系统异常，请稍后刷新页面重试');
		}
	})
}

function refreshWeiboList(uid = null){
	page = 0;
	$("#weibo_tab_page").html('');
	loadBlog(uid);
}

var page = 0;

function loadBlog(uid = null){
	var url = 'userPage.do?m='+page*10+'&n='+(page+1)*10;
	if (uid != null) {
		url += "&user_id=" + uid;
	}

	$.get(url, function(data){
		console.log(data);
		var jsonObj = JSON.parse(data);
		var data = jsonObj.data;
		//weiboList = data;

		var weiboListHtml = "";
		if (data.length > 0) {
			for (var i = 0; i < data.length; i++) {
				var thisData = data[i];
				var head_img = 'img/head/' + thisData.head_image + ".jpg";
				var weiboHtml = '<div class="list_item"><div class="list_item_center"><div class="weibo_message"><div class="weibo_top"><div class="head_img"><a href="person.html?u='+thisData.user_id+'"><img class="weibo_message_img" src = "'+head_img+'"/></a></div><div class="head_nickname"><div class="head_nickname_row"><div class = "head_nickname_size"><a href="person.html?u='+thisData.user_id+'">'+thisData.nickname+'</a></div>'+(thisData.can_delete == '1'? '<div class="delete_btn" data-bid="'+thisData.blog_id+'" data-toggle="modal" data-target="#deleteModal">&#xe634;</div>':'')+'</div><div class = "time_size">'+formatDateTime(thisData.time)+'</div></div></div><div class="div_message_mid"><div class="textarea_message" >'+thisData.content+'</div></div>';
				if(thisData.reblog_user_id != "") {
					// 显示转发的原微博
					weiboHtml += '<div class="transmit"><div class="transmit_name"><a href="detail.html?b='+thisData.reblog_id+'" target="_blank">@'+thisData.reblog_nickname+'</a></div><div class="transmit_name_content">'+thisData.reblog_content+'</div></div>';
				}
					weiboHtml += '<div class="div_message_bottom"><div class="btn_bottom btn_reblog" data-bid="'+thisData.blog_id+'" data-toggle="modal" data-target="#reblogModal" data-reuser="'+thisData.nickname+'" data-recontent="'+thisData.content+'">&#xe617; 转&nbsp;发</div><div class="btn_bottom comment_btn" data-bid="'+thisData.blog_id+'">&#xe62f; 评  论</div><div class="btn_bottom like_btn'+(thisData.liked == "1" ? " like_btn_liked" : "")+'" data-bid="'+thisData.blog_id+'">&#xe604; <span class="like_btn_num">'+thisData.like_num+'</span></div></div></div></div></div>';

				weiboListHtml += weiboHtml;
			}
			$("#weibo_tab_page").append(weiboListHtml);
			page += 1;

			// 以上列表元素会在载入后绑定点击事件
			$(".like_btn").click(function(){
				var _this = $(this);
				var bid = $(this).attr('data-bid');
				console.log(bid);
				if (!$(this).hasClass('like_btn_liked')) {
					// 未赞，现在点赞
					$.post('likeBlog.do',{
						blog_id: bid
					}, function(data){
						console.log(data);
						try{
							var jsonObj = JSON.parse(data);
							if (jsonObj.error == 0) {
								_this.addClass('like_btn_liked');
								var num_span = _this.find('.like_btn_num');
								var num = num_span.html();
								console.log(num);

								num_span.html(parseInt(num) + 1 + "");
							}
						}catch(ex){

						}
					})
				}else{
					// 已赞，现在取消点赞
					$.post('unlikeBlog.do',{
						blog_id: bid
					}, function(data){
						console.log(data);
						try{
							var jsonObj = JSON.parse(data);
							if (jsonObj.error == 0) {
								_this.removeClass('like_btn_liked');
								var num_span = _this.find('.like_btn_num');
								var num = num_span.html();
								console.log(num);

								num_span.html(parseInt(num) - 1 + "");
							}
						}catch(ex){

						}
					})

				}
			})

			$(".comment_btn").click(function(){
				window.open('detail.html?b='+$(this).attr("data-bid"));
			})

			if (data.length < 10) {
				$(".load_more_btn").text("没有更多了");
			}else{
				$(".load_more_btn").text("点击加载更多");
			}
		}else{
			$(".load_more_btn").text("没有更多了");
		}
		
	})
}

function formatDateTime(inputTime) {    
	var timeInt = parseInt(inputTime);
    var date = new Date(timeInt);  
    var y = date.getFullYear();    
    var m = date.getMonth() + 1;    
    m = m < 10 ? ('0' + m) : m;    
    var d = date.getDate();    
    d = d < 10 ? ('0' + d) : d;    
    var h = date.getHours();  
    h = h < 10 ? ('0' + h) : h;  
    var minute = date.getMinutes();  
    var second = date.getSeconds();  
    minute = minute < 10 ? ('0' + minute) : minute;    
    second = second < 10 ? ('0' + second) : second;   
    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;    
}

var reblogId = -1;
var inputedReblog = "";

$("#reblogModal").on('show.bs.modal', function(e){
	var button = $(e.relatedTarget);
	reblogId = button.data('bid');
	$("#modal_nickname").html(button.data('reuser'));
	$("#modal_content").html(button.data('recontent'));

	$("#reblog_textarea").val('');
	$("#reblog_textarea").focus();
})

$("#reblog_submit_btn").click(function(){
	if (inputedReblog.length == 0) {
		$("#reblog_textarea").focus();
		return;
	}
	if (reblogId == -1) {
		return;
	}

	reblogWeibo(inputedReblog, reblogId);

})
//输入框计数
function getBLen(str) {  
    if (str == null) return 0;  
    if (typeof str != "string"){  
        str += "";  
    }  
    return str.replace(/[^\x00-\xff]/g,"01").length;  
}

$("#reblog_textarea").bind('input propertychange', function(){
	// $("#submitBtn").removeAttr("disabled");

	// 计算个性签名字数
	var comment = $("#reblog_textarea").val();
	var wordCount = getBLen(comment);
	if (wordCount > 140) {
		$("#reblog_textarea").val(inputedReblog);
	}else{
		inputedReblog = comment;
	}
	$("#reblog_word_counter").text(getBLen($("#reblog_textarea").val()));
})

function reblogWeibo(content, blogId){
	$.post('postBlog.do', {
		content: content,
		reblog_id: blogId
	}, function(data){
		try{
			var jsonObj = JSON.parse(data);
			if (jsonObj.error == 0) {

				reblogId = -1;
				$("#reblog_textarea").val('');
				inputedReblog = '';
				$("#reblogModal").modal('hide');

				page = 0;
				$("#weibo_area").html('');
				loadBlog();

			}else if (jsonObj.error == 220) {
				window.location.href = "login.html";
			}else{
				alert('系统异常，请稍后重试');
			}
		}catch(ex){
			console.log(ex);
			alert('系统异常，请稍后重试');
		}
	})
}

var deleteBlogId = -1;
$("#deleteModal").on('show.bs.modal', function(e){
	var button = $(e.relatedTarget);
	deleteBlogId = button.data('bid');
})

$("#delete_comfirm_btn").click(function(){
	if (deleteBlogId == -1) {
		return;
	}

	$.post('deleteWeibo.do', {
		blog_id: deleteBlogId
	}, function(data){
		try{
			console.log(data);
			var jsonObj = JSON.parse(data);
			if (jsonObj.error == 0) {
				deleteBlogId = -1;
				// page = 0;
				// $("#weibo_area").html('');
				// loadBlog();
				refreshWeiboList(thisUid);
				$("#deleteModal").modal('hide');
			}else if (jsonObj.error == 220) {
				window.location.href = "index.html";
			}else{
				alert('系统异常，请稍后重试');
			}
		}catch(ex){
			console.log(ex)
			alert('系统异常，请稍后重试');
		}
	})
})

</script>

</body>
</html>